/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.phoenix.repository.handler;

import javax.jcr.AccessDeniedException;
import javax.jcr.InvalidItemStateException;
import javax.jcr.ItemExistsException;
import javax.jcr.PathNotFoundException;
import javax.jcr.ReferentialIntegrityException;
import javax.jcr.RepositoryException;
import javax.jcr.ValueFormatException;
import javax.jcr.lock.LockException;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.nodetype.NoSuchNodeTypeException;
import javax.jcr.version.VersionException;

import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 * Jigsaw server
 * 
 * @author <a href="shamphone@gmail.com">Li XiongFeng</a>
 * @date 2012-5-5
 * @version 1.0.0
 */
public class GeneralContentHandler extends DefaultHandler {
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator)
	 */
	@Override
	public void setDocumentLocator(Locator locator) {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.xml.sax.ContentHandler#startDocument()
	 */
	@Override
	public void startDocument() throws SAXException {
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.xml.sax.ContentHandler#endDocument()
	 */
	@Override
	public void endDocument() throws SAXException {
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String,
	 * java.lang.String)
	 */
	@Override
	public void startPrefixMapping(String prefix, String uri) throws SAXException {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
	 */
	@Override
	public void endPrefixMapping(String prefix) throws SAXException {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.xml.sax.ContentHandler#startElement(java.lang.String,
	 * java.lang.String, java.lang.String, org.xml.sax.Attributes)
	 */
	@Override
	public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
		try {
			if (qName.equalsIgnoreCase("node")) {
				startNode(atts.getValue("name"));
			} else if (qName.equalsIgnoreCase("property")) {
				startProperty(atts.getValue("name"));
			} else if (qName.equalsIgnoreCase("value")) {
				startValue();
			}
		} catch (RepositoryException ex) {
			throw new SAXException(ex);
		}

	}

	/**
	 * 
	 * @param name
	 * @throws RepositoryException
	 * @throws LockException
	 * @throws ConstraintViolationException
	 * @throws VersionException
	 * @throws PathNotFoundException
	 * @throws ItemExistsException
	 */
	protected void startNode(String name) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, RepositoryException {

	}

	/**
	 * 
	 * @param name
	 * @throws RepositoryException
	 */
	protected void startProperty(String name) throws RepositoryException {

	}

	/**
	 * 
	 */
	protected void startValue() {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.xml.sax.ContentHandler#characters(char[], int, int)
	 */
	@Override
	public void characters(char[] ch, int start, int length) throws SAXException {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.xml.sax.ContentHandler#endElement(java.lang.String,
	 * java.lang.String, java.lang.String)
	 */
	@Override
	public void endElement(String uri, String localName, String qName) throws SAXException {
		try {
			if (qName.equalsIgnoreCase("node")) {
				endNode();
			} else if (qName.equalsIgnoreCase("property")) {
				endProperty();
			} else if (qName.equalsIgnoreCase("value")) {
				endValue();
			}
		} catch (RepositoryException ex) {
			throw new SAXException(ex);
		}
	}

	/**
	 * 
	 * @param name
	 * @throws RepositoryException
	 * @throws NoSuchNodeTypeException
	 * @throws LockException
	 * @throws VersionException
	 * @throws ReferentialIntegrityException
	 * @throws InvalidItemStateException
	 * @throws ConstraintViolationException
	 * @throws ItemExistsException
	 * @throws AccessDeniedException
	 */
	protected void endNode() throws AccessDeniedException, ItemExistsException, ConstraintViolationException, InvalidItemStateException, ReferentialIntegrityException, VersionException,
			LockException, NoSuchNodeTypeException, RepositoryException {

	}

	/**
	 * 
	 * @param name
	 * @throws RepositoryException
	 * @throws ConstraintViolationException
	 * @throws LockException
	 * @throws VersionException
	 * @throws ValueFormatException
	 */
	protected void endProperty() throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {

	}

	/**
	 * @throws ValueFormatException
	 * 
	 */
	protected void endValue() throws ValueFormatException {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
	 */
	@Override
	public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String,
	 * java.lang.String)
	 */
	@Override
	public void processingInstruction(String target, String data) throws SAXException {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String)
	 */
	@Override
	public void skippedEntity(String name) throws SAXException {

	}
}
